<template>
  <div class="admin-dashboard">
    <!-- 欢迎区域 -->
    <div class="welcome-section">
      <div class="welcome-content">
        <h1 class="welcome-title">
          <el-icon class="welcome-icon">
            <Sunny />
          </el-icon>
          {{ getGreeting() }}，超级管理员！
        </h1>
        <p class="welcome-desc">欢迎回到 OrangeHire 管理控制台，今天也要加油哦～</p>
      </div>
      <div class="welcome-time">
        <div class="current-time">{{ currentTime }}</div>
        <div class="current-date">{{ currentDate }}</div>
      </div>
    </div>

    <!-- 统计卡片 -->
    <el-row :gutter="20" class="stats-row">
      <el-col :xs="24" :sm="12" :md="6">
        <div class="stat-card">
          <div class="stat-icon enterprise">
            <el-icon>
              <OfficeBuilding />
            </el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalEnterprises }}</div>
            <div class="stat-label">注册企业</div>
          </div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <div class="stat-card">
          <div class="stat-icon users">
            <el-icon>
              <User />
            </el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalUsers }}</div>
            <div class="stat-label">企业用户</div>
          </div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <div class="stat-card">
          <div class="stat-icon jobs">
            <el-icon>
              <Briefcase />
            </el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalJobs }}</div>
            <div class="stat-label">发布职位</div>
          </div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :md="6">
        <div class="stat-card">
          <div class="stat-icon seekers">
            <el-icon>
              <UserFilled />
            </el-icon>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalSeekers }}</div>
            <div class="stat-label">求职者</div>
          </div>
        </div>
      </el-col>
    </el-row>

    <!-- 快捷操作 -->
    <div class="quick-actions">
      <h2 class="section-title">快捷操作</h2>
      <el-row :gutter="16">
        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="action-card" @click="$router.push('/admin/enterprise/list')">
            <div class="action-content">
              <el-icon class="action-icon">
                <OfficeBuilding />
              </el-icon>
              <div class="action-text">
                <div class="action-title">企业管理</div>
                <div class="action-desc">查看和管理所有注册企业</div>
              </div>
            </div>
          </el-card>
        </el-col>

        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="action-card" @click="$router.push('/admin/enterprise/users')">
            <div class="action-content">
              <el-icon class="action-icon">
                <User />
              </el-icon>
              <div class="action-text">
                <div class="action-title">用户管理</div>
                <div class="action-desc">管理企业用户账号</div>
              </div>
            </div>
          </el-card>
        </el-col>

        <el-col :xs="24" :sm="12" :md="8">
          <el-card class="action-card" @click="handleComingSoon">
            <div class="action-content">
              <el-icon class="action-icon">
                <DataAnalysis />
              </el-icon>
              <div class="action-text">
                <div class="action-title">数据统计</div>
                <div class="action-desc">查看平台运营数据</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { ElMessage } from 'element-plus'
import {
  Sunny,
  OfficeBuilding,
  User,
  Briefcase,
  UserFilled,
  DataAnalysis
} from '@element-plus/icons-vue'

const currentTime = ref('')
const currentDate = ref('')
let timer: NodeJS.Timeout

const stats = ref({
  totalEnterprises: 156,
  totalUsers: 1234,
  totalJobs: 2567,
  totalSeekers: 8901
})

const getGreeting = () => {
  const hour = new Date().getHours()
  if (hour < 6) return '夜深了'
  if (hour < 9) return '早上好'
  if (hour < 12) return '上午好'
  if (hour < 14) return '中午好'
  if (hour < 18) return '下午好'
  if (hour < 22) return '晚上好'
  return '夜深了'
}

const updateTime = () => {
  const now = new Date()
  currentTime.value = now.toLocaleTimeString('zh-CN', {
    hour12: false,
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  })
  currentDate.value = now.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'long'
  })
}

const handleComingSoon = () => {
  ElMessage.info('功能开发中，敬请期待！')
}

onMounted(() => {
  updateTime()
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
.admin-dashboard {
  padding: 0;
}

.welcome-section {
  /* fallback for old browsers */
  background: #396afc;
  /* Chrome 10-25, Safari 5.1-6 */
  background: -webkit-linear-gradient(to right, #2948ff, #396afc);
  /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  background: linear-gradient(to right, #2948ff, #396afc);
  color: white;
  padding: 40px;
  border-radius: 12px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.welcome-content {
  flex: 1;
}

.welcome-title {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.welcome-icon {
  font-size: 32px;
  color: #ffd700;
}

.welcome-desc {
  font-size: 16px;
  opacity: 0.9;
  margin: 0;
}

.welcome-time {
  text-align: right;
}

.current-time {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 4px;
}

.current-date {
  font-size: 14px;
  opacity: 0.8;
}

.stats-row {
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.stat-icon.enterprise {
  background: #409eff;
}

.stat-icon.users {
  background: #67c23a;
}

.stat-icon.jobs {
  background: #e6a23c;
}

.stat-icon.seekers {
  background: #f56c6c;
}

.stat-content {
  flex: 1;
}

.stat-number {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.quick-actions {
  margin-top: 24px;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 16px 0;
}

.action-card {
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid #e4e7ed;
}

.action-card:hover {
  border-color: #409eff;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(64, 158, 255, 0.2);
}

.action-content {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px;
}

.action-icon {
  font-size: 32px;
  color: #409eff;
}

.action-text {
  flex: 1;
}

.action-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.action-desc {
  font-size: 14px;
  color: #909399;
}

@media (max-width: 768px) {
  .welcome-section {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }

  .welcome-title {
    font-size: 24px;
  }

  .stat-card {
    padding: 20px;
  }

  .stat-number {
    font-size: 24px;
  }
}
</style>
